<%@ page contentType="text/html; charset=utf-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="basePath" value="${pageContext.request.contextPath}"/>
<%--<script src="${basePath}/resources/zheng-admin/js/jquery.media.js"></script>--%>
<style>
    .pdfView{
        position:absolute;
        left:50%;
        top:50%;
        margin:-330px 0 0 -1000px;
    }
</style>
<!--------------------------导入---------------------------->
<input type="hidden" id="volOrItem">
<%--<input type="hidden" id="importResult">--%>
<div id="openImportDataModel" class="modal fade pdfView" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="width:1900px;">
    <div class="modal-dialog" style='width:500px;'>
        <div class="modal-content">
            <div class="modal-header<%-- bg-primary--%>" <%--style="background: #455EC5;width: 100%"--%>>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">卷/件数据导入</h4>
            </div>
            <div class="modal-body">
                <form id="importForm" class="form-horizontal form-bordered form-row-strippe" data-toggle="validator" method="post">
                    <div>注意：仅支持.xls、.xlsx格式的文件。</div>
                    <br>
                    <input type="file" id="inputVol-file" name="file" accept=".xls,.xlsx" >
                    <br>
                </form>
                <%--<br>--%>
                <%--<button type="button" id="uploadExcel" onclick="getInputVolValue()" class="btn btn-primary">上传文件</button>
                <div id="errorInfo">
                    <br>
                    <br>
                    <span id="errorSpanInfo" class="danger"></span>
                </div>--%>
            </div>
            <div class="modal-footer">
                <button type="button" id="uploadExcel" onclick="getInputVolValue()" class="btn btn-primary">上传文件</button>
                <button type="button" id="uploadLoading" class="btn btn-primary">请稍后操作，正在上传数据中...</button>
                <br>
                <div id="errorInfo">
                    <span id="errorSpanInfo" style="float:left;color: red;"></span><br>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    $(function () {
        $('#openImportDataModel').on('hide.bs.modal', function () {
            $("#inputVol-file").val("");
            $("#errorSpanInfo").val("");
        });
    });

    /**
     * 点击上传时获取数据
     */
    function getInputVolValue(){
        $("#errorInfo").hide();
        $("#errorSpanInfo").empty();
        var fileInput  = $("#inputVol-file")[0].files[0];
        if(fileInput=="" || fileInput==undefined || fileInput=="undefined"){
            confirmEvent("请添加要导入的Excel。");
        }else {
            var file = $("#inputVol-file")[0].files[0];
            var fd = new FormData();
            fd.append('excelFile', file);
            $.ajax({
                url: "${basePath}/pcwindow/importExcel",
                type: 'POST',
                data: fd,
                async: false,//使用ajax上传文件时,必须添加同步sqync,保证文件流传输不断开
                processData: false,  //tell jQuery not to process the data
                contentType: false,  //tell jQuery not to set contentType
                //这儿的三个参数其实就是XMLHttpRequest里面带的信息。
                beforeSend: function() {
                    $("#uploadExcel").hide();
                    $("#uploadLoading").show();
                },
                success: function (result) {
                    if (result == "success") {
                        $('#openImportDataModel').modal('hide');
                        confirmEvent("上传成功");
                        $table.bootstrapTable('refresh');
                    } else {
                        $("#errorInfo").show();
                        $("#errorSpanInfo").text(result);
                    }
                },
                complete: function () {
                    $("#uploadExcel").show();
                    $("#uploadLoading").hide();
                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    $.confirm({
                        theme: 'dark',
                        animation: 'rotateX',
                        closeAnimation: 'rotateX',
                        title: false,
                        content: textStatus,
                        buttons: {
                            confirm: {
                                text: '确认',
                                btnClass: 'waves-effect waves-button waves-light'
                            }
                        }
                    });
                }
            })
        }
    }

</script>
